using Microsoft.OData.Edm;
using Microsoft.OData.ModelBuilder;
using OData.Shared.Models;

namespace OData.MinimalApi.Configuration;

public  static class EdmModelBuilder
{
	public static IEdmModel GetEdmModel()
	{
		var builder = new ODataConventionModelBuilder();
		// Enable lower camel case for C# client generation
		builder.EnableLowerCamelCase(); 
		var customer = builder.EntitySet<Customer>("Customers").EntityType;
		customer.HasKey(c => c.Id);
		builder.ComplexType<Address>();
		customer.HasMany(c => c.Orders);
		
		var lineItem = builder.EntitySet<LineItem>("LineItems").EntityType;
		lineItem.HasKey(li => li.Id);
		
		var order = builder.EntitySet<Order>("Orders").EntityType;
		order.HasKey(o => o.Id);
		order.ContainsMany(o => o.LineItems);
		
		var product = builder.EntitySet<Product>("Products").EntityType;
		product.HasKey(p => p.Id);
		return builder.GetEdmModel();
	}
}
